/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * PublicGoodProvisionGlobalParametersComponent.java
 *
 * Created on 14/Dez/2011, 21:26:10
 */

package intopo.game.impl.pgp;

import intopo.game.gui.AbstractGlobalParametersComponent;

/**
 *
 * @author <a href="mailto:mariano.pedro@gmail.com">Pedro Mariano</a>
 *
 * @version 1.0 14/Dez/2011
 */
public class PublicGoodProvisionGlobalParametersComponent
	extends AbstractGlobalParametersComponent
{

	/** Creates new form PublicGoodProvisionGlobalParametersComponent */
	public PublicGoodProvisionGlobalParametersComponent ()
	{
		initComponents ();
	}

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
   // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
   private void initComponents() {
      java.awt.GridBagConstraints gridBagConstraints;

      javax.swing.JPanel jPanel2 = new javax.swing.JPanel();
      javax.swing.JLabel jLabel1 = new javax.swing.JLabel();
      binProbabilityFormattedTextField = new javax.swing.JFormattedTextField();
      javax.swing.JPanel jPanel1 = new javax.swing.JPanel();
      javax.swing.JLabel jLabel2 = new javax.swing.JLabel();
      stddevNormalProbabilityFormattedTextField = new javax.swing.JFormattedTextField();

      setBorder(javax.swing.BorderFactory.createTitledBorder("global parameters"));
      setLayout(new java.awt.GridBagLayout());

      jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("strategy parameters"));
      jPanel2.setLayout(new java.awt.BorderLayout());

      jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
      jLabel1.setText("Number bins: ");
      jPanel2.add(jLabel1, java.awt.BorderLayout.CENTER);

      binProbabilityFormattedTextField.setColumns(5);
      binProbabilityFormattedTextField.setToolTipText("Number of bins strategies are divided");
      binProbabilityFormattedTextField.setValue(new Integer (PublicGoodProvisionStrategy.Parameters.probability));
      binProbabilityFormattedTextField.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
         public void propertyChange(java.beans.PropertyChangeEvent evt) {
            binProbabilityFormattedTextFieldPropertyChange(evt);
         }
      });
      jPanel2.add(binProbabilityFormattedTextField, java.awt.BorderLayout.EAST);

      gridBagConstraints = new java.awt.GridBagConstraints();
      gridBagConstraints.gridx = 0;
      gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
      gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
      add(jPanel2, gridBagConstraints);

      jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("standard deviation normal distribution mutate"));
      jPanel1.setLayout(new java.awt.GridBagLayout());

      jLabel2.setText("Provide probability gene: ");
      jPanel1.add(jLabel2, new java.awt.GridBagConstraints());

      stddevNormalProbabilityFormattedTextField.setColumns(5);
      stddevNormalProbabilityFormattedTextField.setToolTipText("<html>\nStandard deviation of the normal distribution used to mutate the gene<br>\nthat represents the probability to provide the good\n</html>");
      stddevNormalProbabilityFormattedTextField.setValue(new Float (PublicGoodProvisionStrategy.Parameters.stddevNormalProbability));
      stddevNormalProbabilityFormattedTextField.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
         public void propertyChange(java.beans.PropertyChangeEvent evt) {
            stddevNormalProbabilityFormattedTextFieldPropertyChange(evt);
         }
      });
      jPanel1.add(stddevNormalProbabilityFormattedTextField, new java.awt.GridBagConstraints());

      gridBagConstraints = new java.awt.GridBagConstraints();
      gridBagConstraints.gridx = 0;
      gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
      add(jPanel1, gridBagConstraints);
   }// </editor-fold>//GEN-END:initComponents

	 private void binProbabilityFormattedTextFieldPropertyChange (java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_binProbabilityFormattedTextFieldPropertyChange
		if (evt.getPropertyName ().equals ("value")) {
			final int value = (Integer) this.binProbabilityFormattedTextField.getValue ();
			final boolean ok = value > 0;
			if (ok) {
				PublicGoodProvisionStrategy.Parameters.probability = value;
			}
			this.update (this.binProbabilityFormattedTextField, ok);

		}
	 }//GEN-LAST:event_binProbabilityFormattedTextFieldPropertyChange

	 private void stddevNormalProbabilityFormattedTextFieldPropertyChange (java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_stddevNormalProbabilityFormattedTextFieldPropertyChange
		if (evt.getPropertyName ().equals ("value")) {
			final float value = (Float) this.stddevNormalProbabilityFormattedTextField.getValue ();
			final boolean ok = value >= 0f && value <= 1f;
			if (ok) {
				PublicGoodProvisionStrategy.Parameters.stddevNormalProbability = value;
			}
			this.update (this.stddevNormalProbabilityFormattedTextField, ok);
		}
	 }//GEN-LAST:event_stddevNormalProbabilityFormattedTextFieldPropertyChange


   // Variables declaration - do not modify//GEN-BEGIN:variables
   private javax.swing.JFormattedTextField binProbabilityFormattedTextField;
   private javax.swing.JFormattedTextField stddevNormalProbabilityFormattedTextField;
   // End of variables declaration//GEN-END:variables

}

// Local Variables:
// mode: java
// mode: flyspell-prog
// ispell-local-dictionary: "british"
// End:
